

rem
bbdoc: Game2d/Artemax interface for LUA scripts.
about: The methods in this type are exposed to the LUA scripting system.
Except the hidden methods. These are used from blitzmax
endrem
Type TArtemaxInterface {expose static noclass hidefields}

	'globals set by the script system when started
	'and used by these methods.
	Global _luaState:Byte ptr
	Global _world:TWorld
	Global _game:TGame
	
	
	Method lKeyDown:Int(k:Int) {rename = "KeyDown" bool}
		Return KeyDown(k)
	End Method

	Method lKeyHit:Int(k:Int) {rename = "KeyHit"}
		Return KeyHit(k)
	End Method
	

'#REGION ---------- entity --------

	
	rem
	bbdoc: Deletes passed entity from the world.
	endrem
	Method lDeleteEntity(e:TEntity) {rename = "DeleteEntity"}
		_world.DeleteEntity(e)
	End Method


	rem
	bbdoc: Sets the renderable visible flag.
	endrem
	Method lSetVisible(e:TEntity, bool:Int) {rename = "SetEntityVisible"}
		GetRenderSystem(0).GetRenderable(e).SetVisible(bool)
	End Method

	
	rem
	bbdoc: Returns true if images of entities collide.
	endrem
	Method lEntityCollide:Int(e1:TEntity, e2:TEntity, boxOnly:Int = False) {bool rename = "EntityCollide" }
	
		Local bag:TBag = GetCollisionSystem().CollidingWith(e1, _game, boxOnly)
		
		'if entity 2 is in the bag, then a hit occured
		If e2.GetId() >= bag.GetSize() Then Return False
		If bag.Get(e2.GetId()) = e2 Then Return True
		Return False
	End Method


	rem
	bbdoc: Returns transform component for passed entity.
	endrem
	Method GetTransformComponent:TTransformComponent(e:TEntity)
		Local mapper:TComponentMapper = TComponentMapper.Create(New TTransformComponent, _world)
		Return TTransformComponent(mapper.Get(e))
	End Method
	
	
	rem
	bbdoc: Returns physics component for passed entity.
	endrem
	Method GetPhysicsComponent:TPhysicsComponent(e:TEntity)
		Local mapper:TComponentMapper = TComponentMapper.Create(New TPhysicsComponent, _world)
		Return TPhysicsComponent(mapper.Get(e))
	End Method
	
	
	rem
	bbdoc: Returns position component for passed entity.
	endrem
	Method GetPositionComponent:TPositionComponent(e:TEntity)
		Local mapper:TComponentMapper = TComponentMapper.Create(New TPositionComponent, _world)
		Return TPositionComponent(mapper.Get(e))
	End Method

	
	rem
	bbdoc: Returns expiration component for passed entity.
	endrem
	Method GetExpirationComponent:TExpirationComponent(e:TEntity)
		Local mapper:TComponentMapper = TComponentMapper.Create(New TExpirationComponent, _world)
		Return TExpirationComponent(mapper.Get(e))
	End Method

	
	rem
	bbdoc: Returns color component for passed entity.
	endrem
	Method GetColorComponent:TColorComponent(e:TEntity)
		Local mapper:TComponentMapper = TComponentMapper.Create(New TColorComponent, _world)
		Return TColorComponent(mapper.Get(e))
	End Method
	
	
'#ENDREGION


'#REGION ---------- images --------

	rem
	bbdoc: Returns the image frame value in the entity renderable.
	endrem
	Method lGetImageFrame:Int(e:TEntity) {rename = "GetImageFrame"}
		Return GetRenderSystem(0).GetRenderable(e).GetFrame()
	End Method
	
	
	rem
	bbdoc: Returns the image in the entity renderable.
	endrem
	Method lGetImage:TImage(e:TEntity) {rename = "GetImage"}
		Return GetRenderSystem(0).GetRenderable(e).GetImage()
	End Method
	
	
	rem
	bbdoc: Returns image from resource manager.
	endrem
	Method lGetResourceImage:TImage(imageName:String, groupName:String = "") {rename = "GetResourceImage"}
		Return TResources.GetImage(imageName, groupName)
	End Method
		
'#endregion


'#REGION ---------- systems -------

	Method GetCollisionSystem:TCollisionSystem() {hidden}
		Return TCollisionSystem(_game.GetUpdateSystem(SYSTEM_COLLISION))
	End Method
	

	Method GetRenderSystem:TRenderSystem(index:Int) {hidden}
		Return TRenderSystem(_game.GetRenderSystem())
	End Method

'#endregion	

	
'#REGION ---------- audio ---------


	rem
	bbdoc: Returns sound from resource manager.
	endrem
	Method lGetResourceSound:TSound(soundName:String, groupName:String = "") {rename = "GetResourceSound"}
		Return TResources.GetSound(soundName, groupName)
	End Method


	rem
	bbdoc: Plays sound previously loaded in the resouce manager.
	returns: Used Channel.
	endrem
	Method lPlaySound:TChannel(soundName:String, groupName:String = "",  ..
								volume:Float, channel:TChannel) {rename = "PlaySound"}
								
		Local s:TSound = TResources.GetSound(soundName, groupName)
		If Not s Then RuntimeError("sound '" + soundName + "' in group '" + groupName + "' not found")
		If s Then Return _game.PlaySound(s, channel, volume)
	End Method
	
	
	rem
	bbdoc: Stops passed audio channel.
	endrem
	Method lStopAudioChannel(c:TChannel) {rename = "StopAudioChannel"}
		c.Stop()
	End Method
	
'#ENDREGION

End Type

